package com.suotuo.module.sys.controller;

import com.suotuo.common.util.Result;
import com.suotuo.module.sys.dao.CategoryDAO;
import com.suotuo.module.sys.entity.Category;
import com.suotuo.module.sys.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author liulubingjava@163.com
 * @date 2019/1/22 17:14
 */
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @RequestMapping("list")
    public Result findAll(){
       Page<Category> categoryPage =  categoryService.findAll();
       return Result.success(categoryPage);
    }
    @RequestMapping("/getone")
    public Result getOne(@RequestParam String categoryId){
        return Result.success(categoryService.getCategory(categoryId));
    }
    @RequestMapping("/saveorupdata")
    public Result savaOrUpdata(@RequestBody Category category){
        categoryService.saveOrUpdate(category,category.getCategoryId());
        return Result.success("保存或修改成功");
    }
    @RequestMapping("/delete/one")
    public Result delete(@RequestParam String categoryId){
        categoryService.deleteOne(categoryId);
        return Result.success("删除成功");
    }
    @RequestMapping("/delete/more")
    public Result deleteMore(@RequestParam List<String> categoryIdList){
        categoryService.deleteMore(categoryIdList);
        return Result.success("删除成功");
    }

}
